package distribution

import (
	"activity_srv/activityclient"
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type SetDistributionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSetDistributionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetDistributionLogic {
	return &SetDistributionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// SetDistribution 设置分销
func (l *SetDistributionLogic) SetDistribution(req *types.SetDistributionRequest) (resp *types.Response, err error) {
	set, err := l.svcCtx.ActivityRpc.SetDistribution(l.ctx, &activityclient.SetDistributionRequest{
		FirstLevelRatio:  req.FirstLevelRatio,
		SecondLevelRatio: req.SecondLevelRatio,
		MinWithdraw:      req.MinWithdraw,
		WithdrawFee:      req.WithdrawFee,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(set), nil
}
